Traditionally, administrating a server on which
Microsoft products are installed has involved learning a number of
administrator tools, such as graphical interfaces based on the
Microsoft Management Console (MMC), known as MMC snap-ins;
many command-line utilities; and perhaps a Windows Management
Instrumentation (WMI) provider or Component Object Model (COM) objects
that administrators can interface with using VBScript. Until the
release of SharePoint 2010, SharePoint Products and Technologies were
no different than other Microsoft products in the number of available
administrator tools. Administrators needed to rely on the Central
Administration website, the SharePoint Products Configuration Wizard,
and the command-line tools stsadm and psconfig. No one tool could do
everything.
Each Microsoft product
also had its own community, which created or extended the built-in
tools to make an administrator’s life easier. The tools an
administrator needed were available, but they were scattered among many
sources. This is all changing now that every administrative task can
potentially be scripted or automated using Windows PowerShell.
The concept for
Windows PowerShell is based on a study commissioned by Microsoft in the
early 2000s. Originally based on the POSIX shell as specified in IEEE
1003.2 and influenced by Perl and UNIX shell, Windows PowerShell is a
command shell and scripting language that is far more powerful than
using the Windows command prompt (cmd.exe). Administrators love
command-line tools because they can be batched together to automate
repetitive tasks or to ensure that a set of tasks are completed again
exactly as they were the last time they were executed. Windows
PowerShell cmdlets offer administrators these same benefits. You can
still use the traditional tools, but Windows PowerShell adds
flexibility and breadth that the traditional tools do not provide.
Note:
Community-led initiatives for previous versions of SharePoint include extensions to stsadm, published at http://stsadm.codeplex.com/;
Windows PowerShell scripts for Windows SharePoint Services 3.0 and
Microsoft Office SharePoint Server 2007 that can be found at http://sharepointpsscripts.codeplex.com/;
and the CodePlex project “PowerShell SharePoint Provider” for Windows
SharePoint Services 2.0 and Microsoft SharePoint Portal Server 2003,
available at http://www.codeplex.com/PSSharePoint.
This section covers the following Windows PowerShell topics.
1. What’s New in Windows PowerShell 2.0
Windows PowerShell 2.0 offers a number of new features and improvements from Windows PowerShell 1.0, including
New cmdlets
Remote Management and background jobs
Windows PowerShell Integrated Scripting Environment (ISE)
Windows PowerShell debugger
Modules
Advanced functions
Transactions
Steppable pipelines
Events
Script internationalization
Online Help
As an IT professional, many of these new
features will interest you. For example, you can remotely manage all
the servers in your farm from your desktop, and when you become
competent in Windows PowerShell, you will be able to create your own
advanced functions using the Windows PowerShell scripting language that
you can then use as cmdlets. In Windows PowerShell 1.0, the only way to
do this was with a developer, using code and deploying files onto your
farm.
Note:
MORE INFO For more information about what’s new in Windows PowerShell 2.0, see http://technet.microsoft.com/en-us/library/dd378784.aspx and http://en.wikipedia.org/wiki/Windows_PowerShell.
Other resources can be found by using your favorite Internet search
engine and entering the keywords What’s New in Windows PowerShell 2.0
or the feature names listed previously.
2. Windows PowerShell Architecture
Why is Windows PowerShell
so important? Windows PowerShell scripting language is object
orientated, built on top of the .NET Framework—.NET Framework 3.5 for
Windows PowerShell 2.0—and based on the C# (pronounced C-sharp)
programming language. This allows Windows PowerShell to access the
underlying object models, to pass objects and their values (properties)
from one Windows PowerShell command to another. This means you have
almost the power of a developer without having to write, compile, and
deploy code. The disadvantage is that it can be all too easy to cause
havoc in your installation.
When the Microsoft product
teams consider the tools they want to provide to administrators, they
build them first on Windows PowerShell. Hence, with the installation of
SharePoint 2010, a large number of administrative tasks can be
completed natively with Windows PowerShell cmdlets, with no need to
install software from community-led initiatives. If any additional
cmdlets are required, you can create them using Windows PowerShell
scripts and the Advanced Functions feature in Windows PowerShell 2.0,
and developers within your organization can create new cmdlets. Using
Windows PowerShell to help administer SharePoint is the way of the
future, so it’s important to start learning to use the built-in cmdlets
as soon as possible.
At first, using Windows
PowerShell may seem daunting, but if you have used the command prompt
(cmd.exe) or have created batch files, you will soon be comfortable
with the Windows PowerShell console. In fact, you can even use the
Windows PowerShell console instead of the command prompt, because all
the commands you currently use, such as dir, cd, and ping, work equally
well in the Windows PowerShell console as they do in the command
prompt. You may need to enclose command-line parameters in quotation
marks to use the commands from within Windows PowerShell, but that is
about the only modification you need to make. So there is no need to
use two different windows to complete your administrative tasks.
Note:
By default, the command
prompt has a black background, but this can be changed. Right-click the
title bar and then select Properties. A Properties dialog box appears
with four tabs: Options, Font, Layout, and Colors. You can change the
font, background color, window size, and more.
There are two ways of using
Windows PowerShell: either through a command-line interface, known as
the Windows PowerShell console (powershell.exe), or through the Windows
PowerShell Interactive Scripting Environment (ISE) graphical interface
(Powershell_ise.exe).
Note:
MORE INFO Following are some resources for more information on Windows PowerShell.
All the same shortcuts that you use at the command prompt work in the Windows PowerShell console.
To pause the display
temporarily when a command is writing output, press Ctrl+S, and then
press Ctrl+S to resume or press Ctrl+C to terminate execution. By
default, up to 50 commands are stored in a buffer. You can move through
the buffer by using the up arrow and down arrow keys to scroll through
the commands so you can easily execute the next or a previous command. The
buffered commands can be displayed from a pop-up window by pressing F7.
Select the command you want to execute using the arrow keys, press
Enter or F9, type the number of the command you want to execute, and
then press Enter. The
buffered commands can be displayed from the command line by typing the
first few characters of the command you want and then pressing F8. The
command-line interface searches though the history buffer for the first
command that begins with the characters you typed. Using
the auto completion capabilities of the Windows PowerShell command
shell, you never need to type the complete name of a command. Type in
the first few characters of the command you want and press Tab to cycle
through all commands and available file names and folders in alphabetic
order, or click Shift+Tab to cycle through the commands in reverse
order. To copy
and paste text, right-click the command-line interface title, click
Mark, highlight the text you want to copy, and then right-click the
window title again to copy the selected text automatically into the
Clipboard. Commands
are case insensitive and can be batched together and placed in a text
file. By calling that file in the command-line window, the commands in
the file are executed. These text files have an extension of .bat,
.cmd, .vbs, or in the case of Windows PowerShell, .ps1. Commands in
these files can be executed outside the command window by calling the
file from the Run line or by double-clicking the file in Windows
Explorer. Arguments
can be sent to the command file being called. The arguments passed to
your command file are stored in memory and accessed using variables.
You can also create variables to store values needed as you complete a
task. In Windows PowerShell, you reference variables by preceding the
variable name by a dollar sign ($). Output
from a command can be directed to a file named to the right of >.
This will overwrite the file if it already exists. To redirect the
output but append it to the file, use >>. Error messages that
result from running a command can be redirected to a file named to the
right of 2>, or they can be appended to a file by using 2>> or
sent to the same destination as the standard output by using
2>&1. You can execute many commands on the same line. In Windows PowerShell, you separate commands using the semicolon character (;). Redirect the output of one command as input to another command by separating both command with a ’|’, known as a pipe.
For example, dir | sort | more will display a sorted list of files in
the current directory one page at a time. The pipe is the symbol
located above the backslash on most keyboards. Aliases and shortcuts
can be substituted for commonly used commands. For example, the
ForEach-Object cmdlet can be replaced with ForEach or even with the
percentage character, %. The question mark character, ?, can be used in
place of Where or Where-Object. You can also use Get-Alias to return a
list of aliases. Note that the use of aliases in scripts can make them
difficult to understand.
Examples of these shortcuts can be found throughout this book.
|